package jp.co.takapy.baycity.server.controller.test;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;

import jp.co.takapy.baycity.server.model.StationMst;
import jp.co.takapy.baycity.server.service.LineRegistTest;

import org.slim3.controller.Controller;
import org.slim3.controller.Navigation;
import org.slim3.datastore.Datastore;
import org.slim3.util.RequestMap;

public class HtmlinfoController extends Controller {

    private final static Logger log = Logger.getLogger(TimeparseController.class.getName());

    private LineRegistTest service = new LineRegistTest();

    @Override
    public Navigation run() throws Exception {

        Date date = new Date();

        RequestMap rm = new RequestMap(request);
        log.info(rm.toString());

        String lineId = (String) rm.get("lineId");
        log.info(lineId);

        Map<String, Object> input = new HashMap<String, Object>();
        input.put("lineId", "1");
        input.put("lineName", "浦安線");
        input.put("recievedDate", date);
        input.put("stationId", "H-10");
        input.put("stationName", "浦安駅入り口");
        input.put("directionUp", "新浦安駅行き");
        input.put("directionDown", "浦安駅行き");

        StationMst data = service.regist(input);
        StationMst out = Datastore.get(StationMst.class, data.getLineNo());
        log.info(out.getLineNo().toString());
        log.info(out.getLineName());
        log.info(out.getStationId());
        log.info(out.getStationName());
        SimpleDateFormat sf = new SimpleDateFormat("yyyy/MM/dd");
        log.info(sf.format(out.getRevicedDate()));
        log.info(out.getDirectionUp());
        log.info(out.getDirectionDown());

        return forward("htmlinfo.jsp");
    }
}
